﻿using System;
using System.Collections;
using System.Data;
using System.Text;
using System.Xml;
using BusinessLogic.ClassFactory;
using DataAccess;
using Model.Data;
using Common;

namespace BusinessLogic.BusinessRules
{
    /// <summary>
    /// Sections 的摘要说明。
    /// </summary>
    public class Sections : BaseClass
    {
        // 位置结构体，用于发布时取当前位置
        public struct Position
        {
            public string strName;	// 名称
            public string strHref;	// 链接
            public Position(string Name, string Href)
            {
                strName = Name;
                strHref = Href;
            }
        }

        private SessionUser _sessionUser;

        public SessionUser SessionUser
        {
            get { return _sessionUser; }
            set { _sessionUser = value; }
        }

        #region 必有属性

        public Model.Data.SectionsData.SectionsRow DataItem
        {
            get
            {
                return (Model.Data.SectionsData.SectionsRow)base.m_CurrentRow;
            }
            set
            {
                base.m_CurrentRow = value;
            }
        }

        private Model.Data.SectionsData m_Data
        {
            get
            {
                return (Model.Data.SectionsData)base.m_DataSet;
            }
            set
            {
                base.m_DataSet = value;
            }
        }

        public override int Count
        {
            get
            {
                return this.m_Data.Sections.Count;
            }
        }

        #endregion 必有属性

        #region 构造函数

        public Sections(DataAccess.DBManager m_DBManager, DataAccess.BaseAccess m_Access)
            : base(m_DBManager, m_Access)
        {
        }

        #endregion 构造函数

        #region 必须重载方法

        /// <summary>
        /// 根据数据集中索引,设置当前数据行
        /// </summary>
        /// <param name="n_index">数据集中的索引</param>
        public override void SelectRow(int n_index)
        {
            if (m_Data != null && m_Data.Sections.Rows.Count > n_index)
            {
                DataItem = m_Data.Sections[n_index];
            }
        }

        /// <summary>
        /// 实现更新
        /// </summary>
        /// <returns></returns>
        protected override int OnUpdate()
        {
            return m_Access.Update(this.m_DataSet);
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        protected override bool OnDelete(int ID)
        {
            return true;
        }

        public override void NewDataSet()
        {
            this.m_Data = new SectionsData();
            m_CurrentRow = m_Data.Sections.NewSectionsRow();
        }

        public override void SetDataSet(DataSet m_DataSet)
        {
            this.m_DataSet = m_DataSet;
        }

        public override bool OnInsert()
        {
            this.DataItem.intSectionID = this.GetNextSeed();
            this.m_Data.Sections.Rows.Add(this.m_CurrentRow);
            return true;
        }

        #endregion 必须重载方法

        #region 业务属性

        public Model.Data.SectionsData Data
        {
            get
            {
                return (Model.Data.SectionsData)base.m_DataSet;
            }
            set
            {
                base.m_DataSet = value;
            }
        }

        private WebSite _ParentWebSite = null;

        /// <summary>
        /// 父站点
        /// </summary>
        public WebSite ParentWebSite
        {
            get
            {
                if (_ParentWebSite == null)
                {
                    BusinessLogic.ClassFactory.WebSiteFactory objFactory = new BusinessLogic.ClassFactory.WebSiteFactory(this.m_DBManger);
                    _ParentWebSite = objFactory.Creator(this.DataItem.intWSID);
                }
                return _ParentWebSite;
            }
        }

        #endregion 业务属性

        /// <summary>
        ///   获取特定栏目ID下单页文章列表的XML数据
        /// </summary>
        /// <param name="intTotalCount">总记录数,如果需要分页,此值将被忽略,-1:取所有记录</param>
        /// <returns>string</returns>
        public string GetSinglePageArticleXML(int intTotalCount, string strArticleStatusSql, bool bolIsGlobal, bool bolFilterSame, bool bolShowInIndex, SessionUser sessionUser, int intSectionID, XmlTextWriter writer, ArrayList aryArticleIDParam)
        {
            // 要操作的文章ID数组
            ArrayList aryArticleID = this.GetIssueArticleIDs(intTotalCount, true, strArticleStatusSql, bolIsGlobal, bolFilterSame, sessionUser, intSectionID, aryArticleIDParam);
            if (aryArticleID == null)
            {
                // 该栏目下没有文章
                return string.Empty;
            }

            // 获取文章的XML字符串
            string strXml = string.Empty;
            StringBuilder sbXML = new StringBuilder();
            XmlTextWriter objWriter = null;
            if (writer != null)
            {
                objWriter = writer;
            }
            try
            {
                if (objWriter == null)
                {
                    objWriter = new XmlTextWriter(new System.IO.StringWriter(sbXML));
                }

                //objWriter.WriteStartDocument();
                //objWriter.WriteStartElement("TMPL");

                ArticleFactory objArticleFactory = new ArticleFactory(this.m_DBManger);
                Article objArticle = objArticleFactory.NewInstance();
                objArticle.SessionUser = this.SessionUser;
                bool bolisrefer = false;
                if (!this.DataItem.IsintStateReferNull())
                {
                    if (this.DataItem.intStateRefer == (int)Common.Utility.StateRefer.Yes)
                    {
                        bolisrefer = true;
                    }
                }
                objArticle.GetManyArticlesNoContentXml(objWriter, aryArticleID, bolShowInIndex, bolisrefer, this.DataItem.intSectionID);

                //objWriter.WriteEndElement();
                //objWriter.WriteEndDocument(); ;
                objWriter.Flush();
            }
            finally
            {
                if (objWriter == null)
                {
                    objWriter.Close();
                }
            }

            return sbXML.ToString();
        }

        /// <summary>
        ///   获取单页文章列表的XML数据
        /// </summary>
        /// <param name="intTotalCount">总记录数,如果需要分页,此值将被忽略,-1:取所有记录</param>
        /// <returns>string</returns>
        public string GetSinglePageArticleXML(int intTotalCount, string strArticleStatusSql, bool bolIsGlobal, bool bolFilterSame, bool bolShowInIndex, SessionUser sessionUser, int intSectionCount)
        {
            // 获取文章的XML字符串
            string strXml = string.Empty;
            StringBuilder sbXML = new StringBuilder();
            XmlTextWriter objWriter = null;

            // 要操作的文章ID数组
            ArrayList aryArticleID = this.GetIssueArticleIDs(intTotalCount, true, strArticleStatusSql, bolIsGlobal, bolFilterSame, sessionUser);
            if (aryArticleID == null)
            {
                // 该栏目下没有文章
                return string.Empty;
            }


            try
            {
                objWriter = new XmlTextWriter(new System.IO.StringWriter(sbXML));

                objWriter.WriteStartDocument();
                objWriter.WriteStartElement("TMPL");

                //ArticleFactory objArticleFactory = new ArticleFactory(this.m_DBManger);
                //Article objArticle = objArticleFactory.NewInstance();
                //objArticle.SessionUser = this.SessionUser;
                //objArticle.ParentPath = this.DataItem.IschvParentPathNull() ? "" : this.DataItem.chvParentPath;
                //objArticle.PageName = this.DataItem.IschvPageNameNull() ? "" : this.DataItem.chvPageName;

                for (int i = 0; i < intSectionCount; i++)
                {
                    bool bolisrefer = false;
                    if (!this.DataItem.IsintStateReferNull())
                    {
                        if (this.DataItem.intStateRefer == (int)Common.Utility.StateRefer.Yes)
                        {
                            bolisrefer = true;
                        }
                    }
                    GetSinglePageArticleXML(intTotalCount, strArticleStatusSql, bolIsGlobal, bolFilterSame, bolShowInIndex, sessionUser, this.DataItem.intSectionID, objWriter, aryArticleID);

                    this.SelectRow(i + 1);
                }

                //objArticle.GetManyArticlesNoContentXml(objWriter, aryArticleID, bolShowInIndex, bolisrefer, this.DataItem.intSectionID);

                objWriter.WriteEndElement();
                objWriter.WriteEndDocument(); ;
                objWriter.Flush();
            }
            finally
            {
                objWriter.Close();
            }

            return sbXML.ToString();
        }

        /// <summary>
        ///   获取栏目下所有文章列表的XML数据
        /// </summary>
        /// <param name="intTotalCount">总记录数,如果需要分页,此值将被忽略,-1:取所有记录</param>
        /// <returns>string</returns>
        public string GetSinglePageParentAllArticleXML(int intTotalCount, string strArticleStatusSql, bool bolIsGlobal, bool bolShowInIndex, SessionUser sessionUser)
        {
            // 要操作的文章ID数组
            ArrayList aryArticleID = this.GetIssueArticleIDs(intTotalCount, true, strArticleStatusSql, bolIsGlobal, false, sessionUser);
            if (aryArticleID == null)
            {
                // 该栏目下没有文章
                return string.Empty;
            }

            // 获取文章的XML字符串
            string strXml = string.Empty;
            StringBuilder sbXML = new StringBuilder();
            XmlTextWriter objWriter = null;
            try
            {
                objWriter = new XmlTextWriter(new System.IO.StringWriter(sbXML));

                objWriter.WriteStartDocument();
                objWriter.WriteStartElement("TMPL");

                ArticleFactory objArticleFactory = new ArticleFactory(this.m_DBManger);
                Article objArticle = objArticleFactory.NewInstance();
                objArticle.SessionUser = this.SessionUser;
                bool bolisrefer = false;
                if (!this.DataItem.IsintStateReferNull())
                {
                    if (this.DataItem.intStateRefer == (int)Common.Utility.StateRefer.Yes)
                    {
                        bolisrefer = true;
                    }
                }
                objArticle.GetManyArticlesNoContentXml(objWriter, aryArticleID, bolShowInIndex, bolisrefer, this.DataItem.intSectionID);

                objWriter.WriteEndElement();
                objWriter.WriteEndDocument(); ;
                objWriter.Flush();
            }
            finally
            {
                objWriter.Close();
            }

            return sbXML.ToString();
        }

        /// <summary>
        /// 按指定栏目ID获取要发布的文章ID
        /// </summary>
        /// <param name="intArticleCount">要获取发布的文章数量</param>
        /// <param name="IsReIssue">是否重新发布</param>
        /// <returns>返回ArrayList对象</returns>
        public ArrayList GetIssueArticleIDs(int intArticleCount, bool IsReIssue, string strArticleStatusSql, bool bolIsGlobal, bool bolFilterSame, SessionUser sessionUser, int intSectionIDSource, ArrayList aryArticleIDParam)
        {
            int intSectionID = intSectionIDSource;

            if (!this.DataItem.IsintStateReferNull())
            {
                if (this.DataItem.intStateRefer == (int)Common.Utility.StateRefer.Yes)
                {
                    if (!this.DataItem.IsintReferSectionIDNull())
                    {
                        int intCurrwntSectionID = this.DataItem.intSectionID;
                        FindSectionReferRoot(intCurrwntSectionID, ref intSectionID);
                    }
                }
            }

            if (intArticleCount == -1)
            {
                intArticleCount = 100000;
            }
            ArrayList objReturnArray = null;
            ArtSecRelationFactory objArtSecRelationFactory = new ArtSecRelationFactory(this.m_DBManger);
            StringBuilder strWhere = new StringBuilder();
            if (bolIsGlobal == false)
            {
                strWhere.AppendFormat("select  top {0} ArtSecRelation.*,Article.dtmInTime from ArtSecRelation,Article where Article.intArticleId=ArtSecRelation.intArticleId and ArtSecRelation.intSecArtID in (select intSecArtID from ArtSecRelation where intSectionID in(", intArticleCount);
                strWhere.Append(intSectionID + ",");
                strWhere.Append(string.Format(" 0000) and ArtSecRelation.intWSID={0} ) {1} order by  ArtSecRelation.intSort desc,Article.dtmInTime desc", sessionUser.WebSiteID, strArticleStatusSql));
            }
            else
            {
                strWhere.AppendFormat("select  top {0} ArtSecRelation.*,Article.dtmInTime from ArtSecRelation,Article where Article.intArticleId=ArtSecRelation.intArticleId  ", intArticleCount);
                strWhere.Append(string.Format(" and ArtSecRelation.intWSID={0} and 0=0 {1} order by  ArtSecRelation.intSort desc,Article.dtmInTime desc", sessionUser.WebSiteID, strArticleStatusSql));
            }

            string strWheree = string.Format("select top {0} * from ArtSecRelation where intSecArtID in (select intSecArtID from ArtSecRelation where intSectionID = {1}) order by  intSort desc", intArticleCount, this.DataItem.intSectionID);//
            ArtSecRelation objArtSecRelation = objArtSecRelationFactory.CreatorByFullSql(strWhere.ToString());
            if (objArtSecRelation != null)
            {
                objReturnArray = new ArrayList();
                ArrayList objReturnArrayFiltersame = new ArrayList();
                System.Data.DataTable tblTmp = objArtSecRelation.Data.Tables[0];
                System.Data.DataTable tblResult = tblTmp.Clone();
                foreach (System.Data.DataRow objRow in tblTmp.Rows)
                {
                    if (bolFilterSame == true)
                    {
                        if (objReturnArrayFiltersame.Contains(objRow["intArticleId"]))
                        {
                            continue;
                        }
                        else
                        {
                            // objReturnArray.Add(objRow.intSecArtID);
                            if (aryArticleIDParam != null)
                            {
                                if (aryArticleIDParam.Contains(objRow["intSecArtID"]))
                                {
                                    objReturnArray.Add(objRow["intSecArtID"]);
                                }
                            }
                            else
                            {
                                objReturnArray.Add(objRow["intSecArtID"]);
                            }
                        }
                        objReturnArrayFiltersame.Add(objRow["intArticleId"]);
                    }
                    else
                    {
                        if (aryArticleIDParam != null)
                        {
                            if (aryArticleIDParam.Contains(objRow["intSecArtID"]))
                            {
                                objReturnArray.Add(objRow["intSecArtID"]);
                            }
                        }
                        else
                        {
                            objReturnArray.Add(objRow["intSecArtID"]);
                        }
                    }
                }
            }
            else
            {
                return null;
            }
            return objReturnArray;
        }

        /// <summary>
        /// 获取要发布的文章ID
        /// </summary>
        /// <param name="intArticleCount">要获取发布的文章数量</param>
        /// <param name="IsReIssue">是否重新发布</param>
        /// <returns>返回ArrayList对象</returns>
        public ArrayList GetIssueArticleIDs(int intArticleCount, bool IsReIssue, string strArticleStatusSql, bool bolIsGlobal, bool bolFilterSame, SessionUser sessionUser)
        {
            if (intArticleCount == -1)
            {
                intArticleCount = 100000;
            }
            ArrayList objReturnArray = null;
            ArtSecRelationFactory objArtSecRelationFactory = new ArtSecRelationFactory(this.m_DBManger);
            StringBuilder strWhere = new StringBuilder();
            if (bolIsGlobal == false)
            {
                strWhere.AppendFormat("select  top {0} ArtSecRelation.*,Article.dtmInTime from ArtSecRelation,Article where Article.intArticleId=ArtSecRelation.intArticleId and ArtSecRelation.intSecArtID in (select intSecArtID from ArtSecRelation where intSectionID in(", intArticleCount);
                foreach (Model.Data.SectionsData.SectionsRow objRow in this.Data.Sections.Rows)
                {
                    if (!objRow.IsintStateReferNull())
                    {
                        if (objRow.intStateRefer != (int)Common.Utility.StateRefer.Yes)
                        {
                            strWhere.Append(objRow.intSectionID + ",");
                        }
                        else
                        {
                            int intReferSectionID = -1;
                            int intCurrwntSectionID = objRow.intSectionID;
                            FindSectionReferRoot(intCurrwntSectionID, ref intReferSectionID);
                            strWhere.Append(intReferSectionID + ",");
                        }
                    }
                    else
                    {
                        strWhere.Append(objRow.intSectionID + ",");
                    }
                }
                strWhere.Append(string.Format(" 0000) and ArtSecRelation.intWSID={0} ) {1} order by  ArtSecRelation.intSort desc,Article.dtmInTime desc", sessionUser.WebSiteID, strArticleStatusSql));
            }
            else
            {
                strWhere.AppendFormat("select  top {0} ArtSecRelation.*,Article.dtmInTime from ArtSecRelation,Article where Article.intArticleId=ArtSecRelation.intArticleId  ", intArticleCount);
                strWhere.Append(string.Format(" and ArtSecRelation.intWSID={0} and 0=0 {1} order by  ArtSecRelation.intSort desc,Article.dtmInTime desc", sessionUser.WebSiteID, strArticleStatusSql));
            }

            string strWheree = string.Format("select top {0} * from ArtSecRelation where intSecArtID in (select intSecArtID from ArtSecRelation where intSectionID = {1}) order by  intSort desc", intArticleCount, this.DataItem.intSectionID);//
            ArtSecRelation objArtSecRelation = objArtSecRelationFactory.CreatorByFullSql(strWhere.ToString());
            if (objArtSecRelation != null)
            {
                objReturnArray = new ArrayList();
                ArrayList objReturnArrayFiltersame = new ArrayList();
                System.Data.DataTable tblTmp = objArtSecRelation.Data.Tables[0];
                System.Data.DataTable tblResult = tblTmp.Clone();
                foreach (System.Data.DataRow objRow in tblTmp.Rows)
                {
                    if (bolFilterSame == true)
                    {
                        if (objReturnArrayFiltersame.Contains(objRow["intArticleId"]))
                        {
                            continue;
                        }
                        else
                        {
                            // objReturnArray.Add(objRow.intSecArtID);
                            objReturnArray.Add(objRow["intSecArtID"]);
                        }
                        objReturnArrayFiltersame.Add(objRow["intArticleId"]);
                    }
                    else
                    {
                        objReturnArray.Add(objRow["intSecArtID"]);
                    }
                }
            }
            else
            {
                return null;
            }
            return objReturnArray;
        }

        /// <summary>
        /// 获取父栏目数据
        /// </summary>
        /// <returns></returns>
        public string GetParentSectionXml()
        {
            StringBuilder sbXML = new StringBuilder();
            XmlTextWriter objWriter = new XmlTextWriter(new System.IO.StringWriter(sbXML));
            try
            {
                objWriter.WriteStartDocument();
                objWriter.WriteStartElement("TMPL");

                string strSTID = this.DataItem.intSectionID.ToString();
                string strSTCName = this.DataItem.chvSTCName;
                string chvSTEName = this.DataItem.chvSTEName;
                string txtSeoKeywords = this.DataItem.txtSeoKeywords;
                string txtSeoTitle = this.DataItem.txtSeoTitle;
                string txtSeodescription = this.DataItem.txtSeodescription;
                string strFullPath = "";
                if (SessionUser.EnableParentPath)
                {
                    string strParentPath = (this.DataItem.IschvParentPathNull() ? "shtml\\" : (this.DataItem.chvParentPath.Trim() == "" ? "" : this.DataItem.chvParentPath + "\\"));
                    if (!this.DataItem.IschvPageNameNull())
                    {
                        if (string.IsNullOrEmpty(this.DataItem.chvPageName.Trim()))
                        {
                            if (strParentPath == "")
                            {
                                strParentPath = "shtml\\";
                            }
                        }
                    }
                    if (SessionUser.WebSiteLevel != 1)
                    {
                        strParentPath = SessionUser.VartualPath + "\\" + strParentPath;
                    }

                    if (!System.IO.Directory.Exists(SessionUser.IssuePath + strParentPath))
                    {
                        System.IO.Directory.CreateDirectory(SessionUser.IssuePath + strParentPath);
                    }

                    strFullPath = "/" + strParentPath.Replace("\\", "/") + (this.DataItem.IschvPageNameNull() ? "T" : this.DataItem.chvPageName) + "-" + this.DataItem.intSectionID.ToString() + "." + Common.AppConfig.GetWebFileType();
                }
                else
                {
                    strFullPath = "../shtml/T-" + this.DataItem.intSectionID.ToString() + "." + Common.AppConfig.GetWebFileType();
                }
                string strSTMemo = string.Empty;
                if (!this.DataItem.IstxtSTMemoNull())
                    strSTMemo = this.DataItem.txtSTMemo;
                string strSTMainPic = string.Empty;
                if (!this.DataItem.IschvSectionMainPicNull())
                {
                    strSTMainPic = "../Pcfiles/" + this.DataItem.chvSectionMainPic;
                }
                else
                {
                    strSTMainPic = "../Pcfiles/default.jpg";
                }
                objWriter.WriteStartElement("Section");

                // 栏目ID
                objWriter.WriteStartElement("intSTID");
                objWriter.WriteCData(strSTID);
                objWriter.WriteEndElement();
                // 栏目名称
                objWriter.WriteStartElement("chvSTCName");
                objWriter.WriteCData(strSTCName);
                objWriter.WriteEndElement();
                // 栏目名称
                objWriter.WriteStartElement("chvSTEName");
                objWriter.WriteCData(chvSTEName);
                objWriter.WriteEndElement();
                // 栏目路径
                objWriter.WriteStartElement("chvSTPath");
                objWriter.WriteCData(strFullPath);
                objWriter.WriteEndElement();
                // 栏目简介
                objWriter.WriteStartElement("txtSTMemo");
                objWriter.WriteCData(strSTMemo);
                objWriter.WriteEndElement();
                // 栏目图片
                objWriter.WriteStartElement("chvSectionMainPic");
                objWriter.WriteCData(strSTMainPic);
                objWriter.WriteEndElement();
                // 栏目SEO关键字
                objWriter.WriteStartElement("txtSeoKeywords");
                objWriter.WriteCData(txtSeoKeywords);
                objWriter.WriteEndElement();
                // 栏目SEO标题
                objWriter.WriteStartElement("txtSeoTitle");
                objWriter.WriteCData(txtSeoTitle);
                objWriter.WriteEndElement();
                // 栏目SEO描述
                objWriter.WriteStartElement("txtSeodescription");
                objWriter.WriteCData(txtSeodescription);
                objWriter.WriteEndElement();

                objWriter.WriteEndElement(); // 结束节点Section

                objWriter.WriteEndElement(); // 结束节点TMPL
                objWriter.WriteEndDocument();
                objWriter.Flush();
            }
            finally
            {
                objWriter.Close();
            }
            return sbXML.ToString();
        }

        /// <summary>
        /// 获取单条栏目相关Xml数据
        /// </summary>
        /// <returns></returns>
        public string GetOneSectionXml()
        {
            StringBuilder sbXML = new StringBuilder();
            XmlTextWriter objWriter = new XmlTextWriter(new System.IO.StringWriter(sbXML));
            try
            {
                objWriter.WriteStartDocument();
                objWriter.WriteStartElement("TMPL");

                string strSTID = this.DataItem.intSectionID.ToString();
                string strSTCName = this.DataItem.chvSTCName;
                string chvSTEName = this.DataItem.chvSTEName;
                string txtSeoKeywords = this.DataItem.txtSeoKeywords;
                string txtSeoTitle = this.DataItem.txtSeoTitle;
                string txtSeodescription = this.DataItem.txtSeodescription;
                string strSectionMainPic = this.DataItem.chvSectionMainPic;

                objWriter.WriteStartElement("Section");

                // 栏目ID
                objWriter.WriteStartElement("intSTID");
                objWriter.WriteCData(strSTID);
                objWriter.WriteEndElement();
                // 栏目名称
                objWriter.WriteStartElement("chvSTCName");
                objWriter.WriteCData(strSTCName);
                objWriter.WriteEndElement();
                // 栏目名称EN
                objWriter.WriteStartElement("chvSTEName");
                objWriter.WriteCData(chvSTEName);
                objWriter.WriteEndElement();
                // 栏目SEO关键字
                objWriter.WriteStartElement("txtSeoKeywords");
                objWriter.WriteCData(txtSeoKeywords);
                objWriter.WriteEndElement();
                // 栏目SEO标题
                objWriter.WriteStartElement("txtSeoTitle");
                objWriter.WriteCData(txtSeoTitle);
                objWriter.WriteEndElement();
                // 栏目SEO描述
                objWriter.WriteStartElement("txtSeodescription");
                objWriter.WriteCData(txtSeodescription);
                objWriter.WriteEndElement();
                // 展示图
                objWriter.WriteStartElement("chvSectionMainPic");
                objWriter.WriteCData(strSectionMainPic);
                objWriter.WriteEndElement();

                objWriter.WriteEndElement(); // 结束节点Section

                objWriter.WriteEndElement(); // 结束节点TMPL
                objWriter.WriteEndDocument();
                objWriter.Flush();
            }
            finally
            {
                objWriter.Close();
            }
            return sbXML.ToString();
        }

        public ArrayList GetIssueArticleIDs(bool isIssueAll)
        {
            ArrayList objReturnArray = null;
            using (DBManager _dbManage = new DBManager())
            {
                ArtSecRelationFactory objFactory = new ArtSecRelationFactory(_dbManage);
                StringBuilder strWhere = new StringBuilder();
                if (!isIssueAll)
                {
                    strWhere.AppendFormat(string.Format(" intSectionID = {0}  and intState={1}", this.DataItem.intSectionID, (int)Utility.ArticleState.NoIssue));//
                }
                else
                {
                    strWhere.AppendFormat(string.Format(" intSectionID = {0}  ", this.DataItem.intSectionID));//
                }
                //strWhere.Append(" order by intSort desc,dtmInTime desc");
                ArtSecRelation objArtSecRelation = objFactory.CreatorBySql(strWhere.ToString());
                if (objArtSecRelation != null)
                {
                    objReturnArray = new ArrayList();
                    foreach (Model.Data.ArtSecRelationData.ArtSecRelationRow objRow in objArtSecRelation.Data.ArtSecRelation.Rows)
                    {
                        objReturnArray.Add(objRow.intSecArtID);
                    }
                }
                else
                {
                    return null;
                }
            }
            return objReturnArray;
        }

        // 获取栏目的真实URL
        public string GetSectionRealUrl()
        {
            return string.Format("{0}/{1}", this.ParentWebSite.DataItem.chvWebUrl, this.DataItem.chvFullPath).Replace("\\", "/");
        }

        // 获取栏目的真实URL
        public string GetSectionRealUrl(string strFullPath)
        {
            return string.Format("{0}/{1}", this.ParentWebSite.DataItem.chvWebUrl, strFullPath).Replace("\\", "/");
        }

        /// <summary>
        /// 获取分页的栏目文章的XML
        /// </summary>
        /// <param name="intPagesize">每页的记录数</param>
        /// <returns></returns>
        public string[] GetMultiPageArticleXML(int intPagesize, bool blnPreview, string strArticleStatusSql, bool bolIsGlobal, bool bolFilterSame, SessionUser sessionUser, string strFirstPageName, string strPrevPageName, string strNextPageName, string strLastPageName)
        {
            ArrayList aryArticleIDs = this.GetIssueArticleIDs(-1, true, strArticleStatusSql, bolIsGlobal, bolFilterSame, sessionUser);

            if (aryArticleIDs == null)
            {
                return null;// 该栏目下无文章
            }

            // 计算总页数
            int intTotalCount = aryArticleIDs.Count;

            int intPageCount = intTotalCount / intPagesize;
            if (intTotalCount > intPageCount * intPagesize)
            {
                intPageCount++;
            }

            // 返回的XML数组
            string[] aryReturnXml = new string[intPageCount];
            int intCurPage = 0;

            // 将文章ID按页分成若干个数组
            for (int i = 0; i < intTotalCount; i += intPagesize)
            {
                int intDim = intPagesize;	// 每页的文章数量
                if (intTotalCount - i < intPagesize)	// 当前页的文章数量不足页大小
                {
                    intDim = intTotalCount - i;
                }
                ArrayList aryTmp = new ArrayList();
                for (int j = 0; j < intDim; j++)
                {
                    int xh = i + j;
                    aryTmp.Add(aryArticleIDs[xh]);
                }
                aryReturnXml[intCurPage] = GetXpageArticleXml(intCurPage, intPageCount, aryTmp, strFirstPageName, strPrevPageName, strNextPageName, strLastPageName);
                if (blnPreview == true)
                {
                    break;	// 预览时只返回第一页的XML
                }
                intCurPage++;
            }

            return aryReturnXml;
        }

        /// <summary>
        /// 获取指定页的文章列表的XML
        /// </summary>
        /// <param name="intCurPage">当前页</param>
        /// <param name="intPageCount">总页数</param>
        /// <param name="aryArticleID">当前页的文章ID数组</param>
        /// <returns></returns>
        public string GetXpageArticleXml(int intCurPage, int intPageCount, ArrayList aryArticleID, string strFirstPageName, string strPrevPageName, string strNextPageName, string strLastPageName)
        {
            // 获取文章的XML字符串
            string strXml = string.Empty;
            StringBuilder sbXML = new StringBuilder();
            XmlTextWriter objWriter = null;
            try
            {
                objWriter = new XmlTextWriter(new System.IO.StringWriter(sbXML));
                using (ArticleFactory objArticleFactory = new ArticleFactory())
                {
                    Article objArticle = objArticleFactory.NewInstance();
                    objArticle.SessionUser = this.SessionUser;
                    objArticle.PageName = this.DataItem.IschvPageNameNull() ? "" : this.DataItem.chvPageName;
                    objArticle.ParentPath = this.DataItem.IschvParentPathNull() ? "" : this.DataItem.chvParentPath;

                    objWriter.WriteStartDocument();
                    objWriter.WriteStartElement("TMPL");

                    // 取不含文章内容的Article的XML字符串
                    // objArticle.GetArticleNocontentXml(this.DataItem.intSTID, objWriter) ;
                    bool bolisrefer = false;
                    if (!this.DataItem.IsintStateReferNull())
                    {
                        if (this.DataItem.intStateRefer == (int)Common.Utility.StateRefer.Yes)
                        {
                            bolisrefer = true;
                        }
                    }
                    objArticle.GetManyArticlesNoContentXml(objWriter, aryArticleID, false, bolisrefer, this.DataItem.intSectionID);

                    // 获取页导航条的html代码
                    this.GetPageNavigation(intCurPage, intPageCount, objWriter, strFirstPageName, strPrevPageName, strNextPageName, strLastPageName);

                    objWriter.WriteEndElement();
                    objWriter.WriteEndDocument(); ;
                    objWriter.Flush();
                }
            }
            finally
            {
                objWriter.Close();
            }

            return sbXML.ToString();
        }

        /// <summary>
        /// 获取页导航条的html代码
        /// </summary>
        /// <param name="intCurPage">当前页,以0为起始页</param>
        /// <param name="intPageCount"></param>
        /// <param name="objWriter"></param>
        public void GetPageNavigation(int intCurPage, int intPageCount, XmlTextWriter objWriter, string strFirstPageName, string strPrevPageName, string strNextPageName, string strLastPageName)
        {
            if (intPageCount < 1)	// 只有多于一页时,才需要页导航
            {
                return;
            }
            string strReturn = string.Empty;
            int intNavigationNumber = 10;

            int intFirstPage = 0;  // 当前要显示的第一页,以0为起始计数
            int intLastPage = 9;	// 当前要显示的最后一页
            int intPrevHalf = 5;	// 当前页链接的前半部分页链接数
            int intNextHalf = 4;	// 当前页链接的后半部分页链接数

            string strFirstName = string.IsNullOrEmpty(strFirstPageName) ? "首页" : strFirstPageName;
            string strLastName = string.IsNullOrEmpty(strLastPageName) ? "尾页" : strLastPageName;
            string strPrevName = string.IsNullOrEmpty(strPrevPageName) ? "上一页" : strPrevPageName;
            string strNextName = string.IsNullOrEmpty(strNextPageName) ? "下一页" : strNextPageName;

            if (intNavigationNumber % 2 == 0)
            {
                intPrevHalf = intNavigationNumber / 2;
                intNextHalf = intNavigationNumber / 2 - 1;
            }
            else
            {
                intPrevHalf = intNavigationNumber / 2;
                intNextHalf = intNavigationNumber / 2;
            }
            intFirstPage = intCurPage - intPrevHalf;
            if (intFirstPage < 1)
            {
                intFirstPage = 0;
                intLastPage = intNavigationNumber - 1;
            }
            else
            {
                intLastPage = intCurPage + intNextHalf;
            }

            if (intLastPage > intPageCount - 1)
            {
                intLastPage = intPageCount - 1;
            }

            string strParentPath = "";
            if (this.SessionUser.EnableParentPath)
            {
                strParentPath = (this.DataItem.IschvParentPathNull() ? "shtml\\" : (this.DataItem.chvParentPath.Trim() == "" ? "" : this.DataItem.chvParentPath + "\\"));
                if (!this.DataItem.IschvPageNameNull())
                {
                    if (string.IsNullOrEmpty(this.DataItem.chvPageName.Trim()))
                    {
                        if (strParentPath == "")
                        {
                            strParentPath = "shtml\\";
                        }
                    }
                }
                if (SessionUser.WebSiteLevel != 1)
                {
                    strParentPath = SessionUser.VartualPath + "\\" + strParentPath;
                }
            }

            // 添加"上一页"链接
            if (intCurPage >= 0)
            {
                if (intCurPage == 0)
                {
                    //strReturn += string.Format("<a href='#'>Home</a>&nbsp;");
                    strReturn += string.Format("<a href='#'>{0}</a>&nbsp;", strFirstName);
                }
                else if (intCurPage == 1)
                {
                    //strReturn += string.Format("<a href='T-{0}.{1}'>Previous</a>&nbsp;", this.DataItem.intSectionID, Common.AppConfig.GetWebFileType());
                    if (this.SessionUser.EnableParentPath)
                    {
                        strReturn += string.Format("<a href='{0}.{1}'>{2}</a>&nbsp;", "/" + strParentPath.Replace("\\", "/") + (this.DataItem.IschvPageNameNull() ? "T-" + this.DataItem.intSectionID : (string.IsNullOrEmpty(this.DataItem.chvPageName.Trim()) ? "T-" + this.DataItem.intSectionID : this.DataItem.chvPageName)), Common.AppConfig.GetWebFileType(), strPrevName);
                    }
                    else
                    {
                        strReturn += string.Format("<a href='T-{0}.{1}'>{2}</a>&nbsp;", this.DataItem.intSectionID, Common.AppConfig.GetWebFileType(), strPrevName);
                    }
                }
                else
                {
                    //strReturn += string.Format("<a href='T-{0}--{1}.{2}'>Previous</a>&nbsp;", this.DataItem.intSectionID, intCurPage - 1, Common.AppConfig.GetWebFileType());
                    if (this.SessionUser.EnableParentPath)
                    {
                        strReturn += string.Format("<a href='{0}--{1}.{2}'>{3}</a>&nbsp;", "/" + strParentPath.Replace("\\", "/") + (this.DataItem.IschvPageNameNull() ? "T-" + this.DataItem.intSectionID : (string.IsNullOrEmpty(this.DataItem.chvPageName.Trim()) ? "T-" + this.DataItem.intSectionID : this.DataItem.chvPageName)), intCurPage - 1, Common.AppConfig.GetWebFileType(), strPrevName);
                    }
                    else
                    {
                        strReturn += string.Format("<a href='T-{0}--{1}.{2}'>{3}</a>&nbsp;", this.DataItem.intSectionID, intCurPage - 1, Common.AppConfig.GetWebFileType(), strPrevName);
                    }
                }
            }

            // 依次生成每页的链接
            for (int i = intFirstPage; i <= intLastPage; i++)
            {
                if (i == intCurPage)	// 当前页,无链接
                {
                    if (intPageCount > 1)
                        strReturn += string.Format("<font class='CurPage'>{0}&nbsp;</font>", intCurPage + 1);
                    else
                    {
                        //strReturn += string.Format("<a href=\"#\">Previous</a><font class='CurPage'>{0}&nbsp;</font><a href=\"#\">Next</a>", intCurPage + 1);
                        strReturn += string.Format("<a href=\"#\">{1}</a><font class='CurPage'>{0}&nbsp;</font><a href=\"#\">{2}</a>", intCurPage + 1, strPrevName, strNextName);
                    }
                }
                else
                {
                    if (i == 0)
                    {
                        if (this.SessionUser.EnableParentPath)
                        {
                            strReturn += string.Format("<a href='{0}.{1}'>{2}</a>&nbsp;", "/" + strParentPath.Replace("\\", "/") + (this.DataItem.IschvPageNameNull() ? "T-" + this.DataItem.intSectionID : (string.IsNullOrEmpty(this.DataItem.chvPageName.Trim()) ? "T-" + this.DataItem.intSectionID : this.DataItem.chvPageName)), Common.AppConfig.GetWebFileType(), i + 1);
                        }
                        else
                        {
                            strReturn += string.Format("<a href='T-{0}.{1}'>{2}</a>&nbsp;", this.DataItem.intSectionID, Common.AppConfig.GetWebFileType(), i + 1);
                        }
                    }
                    else
                    {
                        if (this.SessionUser.EnableParentPath)
                        {
                            strReturn += string.Format("<a href='{0}--{1}.{2}'>{3}</a>&nbsp;", "/" + strParentPath.Replace("\\", "/") + (this.DataItem.IschvPageNameNull() ? "T-" + this.DataItem.intSectionID : (string.IsNullOrEmpty(this.DataItem.chvPageName.Trim()) ? "T-" + this.DataItem.intSectionID : this.DataItem.chvPageName)), i, Common.AppConfig.GetWebFileType(), i + 1);
                        }
                        else
                        {
                            strReturn += string.Format("<a href='T-{0}--{1}.{2}'>{3}</a>&nbsp;", this.DataItem.intSectionID, i, Common.AppConfig.GetWebFileType(), i + 1);
                        }
                    }
                }
            }

            // 添加"下一页"链接
            if (intCurPage < intPageCount - 1)
            {
                //strReturn += string.Format("<a href='T-{0}--{1}.{2}'>Next</a>&nbsp;", this.DataItem.intSectionID, intCurPage + 1, Common.AppConfig.GetWebFileType());
                if (this.SessionUser.EnableParentPath)
                {
                    strReturn += string.Format("<a href='{0}--{1}.{2}'>{3}</a>&nbsp;", "/" + strParentPath.Replace("\\", "/") + (this.DataItem.IschvPageNameNull() ? "T-" + this.DataItem.intSectionID : (string.IsNullOrEmpty(this.DataItem.chvPageName.Trim()) ? "T-" + this.DataItem.intSectionID : this.DataItem.chvPageName)), intCurPage + 1, Common.AppConfig.GetWebFileType(), strNextName);
                }
                else
                {
                    strReturn += string.Format("<a href='T-{0}--{1}.{2}'>{3}</a>&nbsp;", this.DataItem.intSectionID, intCurPage + 1, Common.AppConfig.GetWebFileType(), strNextName);
                }
            }
            else if (intCurPage == intPageCount - 1)
            {
                //strReturn += string.Format("<a href='#'>Last</a>&nbsp;");
                strReturn += string.Format("<a href='#'>{0}</a>&nbsp;", strLastName);
            }

            objWriter.WriteStartElement("PageNavigation");
            objWriter.WriteAttributeString("intPageCount", intPageCount.ToString());
            objWriter.WriteCData(strReturn);
            objWriter.WriteEndElement();
        }

        /// <summary>
        /// 获取兄弟栏目xml
        /// </summary>
        /// <param name="intSectionID"></param>
        /// <returns></returns>
        public string GetBrotherSectionListXml(int intSectionID, bool isBrother, bool bolShowInIndex, bool bolRecursionChildren)
        {
            string[] strFilds = new string[15] { "intSectionID", "chvSTCName", "chvSectionMainPic", "dtmInTime", "chvFullPath", "txtSTMemo", "chvSTEName", "txtSeoKeywords ", "txtSeoTitle ", "txtSeodescription ", "chvParentPath ", "chvPageName ", "intReferSectionID ", "txtRemarks ", "chvRedirectUrl " };
            //获取要发布的栏目
            ArrayList objSectionIDList = this.GetSectionIDs(intSectionID, isBrother);
            //生成Xml
            StringBuilder strXml = new StringBuilder();
            XmlTextWriter writer = new XmlTextWriter(new System.IO.StringWriter(strXml));
            writer.WriteStartDocument();
            writer.WriteStartElement("TMPL");

            for (int i = 0; i < objSectionIDList.Count; i++)
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("SELECT ");
                for (int x = 0; x < strFilds.Length; x++)
                {
                    if (x == strFilds.Length - 1)
                    {
                        strSql.Append(strFilds[x].ToString());
                    }
                    else
                    {
                        strSql.Append(strFilds[x].ToString() + ",");
                    }
                }
                strSql.AppendFormat(" FROM [SECTIONS] WHERE INTSECTIONID={0} Order By intSortNo desc,dtmInTime asc", objSectionIDList[i]);
                DataTable tblTmp = this.m_Access.ExecuteDataTable(strSql.ToString());
                DataRow row = tblTmp.Rows[0];
                if (SessionUser.EnableParentPath)
                {
                    string strParentPath = (row["chvParentPath"] == DBNull.Value ? "shtml\\" : (row["chvParentPath"].ToString().Trim() == "" ? "" : row["chvParentPath"].ToString() + "\\"));
                    if (row["chvPageName"] != DBNull.Value)
                    {
                        if (string.IsNullOrEmpty(row["chvPageName"].ToString().Trim()))
                        {
                            if (strParentPath == "")
                            {
                                strParentPath = "shtml\\";
                            }
                        }
                    }
                    if (SessionUser.WebSiteLevel != 1)
                    {
                        strParentPath = SessionUser.VartualPath + "\\" + strParentPath;
                    }

                    if (!System.IO.Directory.Exists(SessionUser.IssuePath + strParentPath))
                    {
                        System.IO.Directory.CreateDirectory(SessionUser.IssuePath + strParentPath);
                    }

                    row["chvFullPath"] = "/" + strParentPath.Replace("\\", "/") + (row["chvPageName"] == DBNull.Value ? "T-" + row["intSectionID"] : (string.IsNullOrEmpty(row["chvPageName"].ToString().Trim()) ? "T-" + row["intSectionID"] : (row["chvPageName"] + (this.SessionUser.EnableSectionID == true ? ("-" + row["intSectionID"]) : "")))) + "." + Common.AppConfig.GetWebFileType();
                }
                else
                {
                    if (bolShowInIndex == true)
                    {
                        row["chvFullPath"] = "shtml/T-" + row["intSectionID"].ToString() + "." + Common.AppConfig.GetWebFileType();
                    }
                    else
                    {
                        row["chvFullPath"] = "../shtml/T-" + row["intSectionID"].ToString() + "." + Common.AppConfig.GetWebFileType();
                    }
                }
                // 修改栏目图片链接
                if (row["chvSectionMainPic"] != DBNull.Value)
                {
                    if (SessionUser.EnableParentPath)
                    {
                        row["chvSectionMainPic"] = "/news/" + this.SessionUser.VartualPath + "/Pcfiles/" + row["chvSectionMainPic"].ToString();
                    }
                    else
                    {
                        if (bolShowInIndex == true)
                        {
                            row["chvSectionMainPic"] = "Pcfiles/" + row["chvSectionMainPic"].ToString();
                        }
                        else
                        {
                            row["chvSectionMainPic"] = "../Pcfiles/" + row["chvSectionMainPic"].ToString();
                        }
                    }
                }
                else
                {
                    if (SessionUser.EnableParentPath)
                    {
                        row["chvSectionMainPic"] = "/news/" + this.SessionUser.VartualPath + "/Pcfiles/default.jpg";
                    }
                    else
                    {
                        if (bolShowInIndex == true)
                        {
                            row["chvSectionMainPic"] = "Pcfiles/default.jpg";
                        }
                        else
                        {
                            row["chvSectionMainPic"] = "../Pcfiles/default.jpg";
                        }
                    }
                }

                writer.WriteStartElement("Section");

                // 添加数据库字段值
                for (int j = 0; j < tblTmp.Columns.Count; j++)
                {
                    if (row[j] != DBNull.Value)
                    {
                        writer.WriteStartElement(tblTmp.Columns[j].ColumnName);
                        writer.WriteCData(row[j].ToString());
                        writer.WriteEndElement();
                    }
                }

                if (bolRecursionChildren)
                {
                    var strRecursionChildSection = this.GetSectionListRecursionXml((int)objSectionIDList[i], false, false, false, this.SessionUser);
                    writer.WriteStartElement("RecursionChildren");
                    writer.WriteRaw(strRecursionChildSection);
                    writer.WriteEndElement();
                }

                writer.WriteEndElement();
            }

            writer.WriteEndElement();
            writer.WriteEndDocument();
            return strXml.ToString();
        }

        /// <summary>
        /// 获取递归栏目xml
        /// </summary>
        /// <param name="intSectionID"></param>
        /// <returns></returns>
        public string GetSectionListRecursionXml(int intSectionID, bool bolShowInIndex, bool startXmlDoc, bool bolContainArticle, SessionUser objSessionUser)
        {
            this.SessionUser = objSessionUser;
            string[] strFilds = new string[15] { "intSectionID", "chvSTCName", "chvSectionMainPic", "dtmInTime", "chvFullPath", "txtSTMemo", "chvSTEName", "txtSeoKeywords ", "txtSeoTitle ", "txtSeodescription ", "chvParentPath ", "chvPageName ", "intReferSectionID ", "txtRemarks ", "chvRedirectUrl " };
            //生成Xml
            StringBuilder strXml = new StringBuilder();
            XmlTextWriter writer = new XmlTextWriter(new System.IO.StringWriter(strXml));
            if (startXmlDoc == true)
            {
                writer.WriteStartDocument();
                writer.WriteStartElement("TMPL");
            }

            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT ");
            for (int x = 0; x < strFilds.Length; x++)
            {
                if (x == strFilds.Length - 1)
                {
                    strSql.Append(strFilds[x].ToString());
                }
                else
                {
                    strSql.Append(strFilds[x].ToString() + ",");
                }
            }
            strSql.AppendFormat(" FROM [SECTIONS] WHERE intParentID={0} Order By intSortNo desc,dtmInTime desc", intSectionID);
            DataTable tblTmp = this.m_Access.ExecuteDataTable(strSql.ToString());
            for (int i = 0; i < tblTmp.Rows.Count; i++)
            {
                DataRow row = tblTmp.Rows[i];
                if (SessionUser.EnableParentPath)
                {
                    string strParentPath = (row["chvParentPath"] == DBNull.Value ? "shtml\\" : (row["chvParentPath"].ToString().Trim() == "" ? "" : row["chvParentPath"].ToString() + "\\"));
                    if (row["chvPageName"] != DBNull.Value)
                    {
                        if (string.IsNullOrEmpty(row["chvPageName"].ToString().Trim()))
                        {
                            if (strParentPath == "")
                            {
                                strParentPath = "shtml\\";
                            }
                        }
                    }
                    if (SessionUser.WebSiteLevel != 1)
                    {
                        strParentPath = SessionUser.VartualPath + "\\" + strParentPath;
                    }

                    if (!System.IO.Directory.Exists(SessionUser.IssuePath + strParentPath))
                    {
                        System.IO.Directory.CreateDirectory(SessionUser.IssuePath + strParentPath);
                    }

                    row["chvFullPath"] = "/" + strParentPath.Replace("\\", "/") + (row["chvPageName"] == DBNull.Value ? "T-" + row["intSectionID"] : (string.IsNullOrEmpty(row["chvPageName"].ToString().Trim()) ? "T-" + row["intSectionID"] : (row["chvPageName"] + (this.SessionUser.EnableSectionID == true ? ("-" + row["intSectionID"]) : "")))) + "." + Common.AppConfig.GetWebFileType();
                }
                else
                {
                    if (bolShowInIndex == true)
                    {
                        row["chvFullPath"] = "shtml/T-" + row["intSectionID"].ToString() + "." + Common.AppConfig.GetWebFileType();
                    }
                    else
                    {
                        row["chvFullPath"] = "../shtml/T-" + row["intSectionID"].ToString() + "." + Common.AppConfig.GetWebFileType();
                    }
                }
                // 修改栏目图片链接
                if (row["chvSectionMainPic"] != DBNull.Value)
                {
                    if (SessionUser.EnableParentPath)
                    {
                        row["chvSectionMainPic"] = "/news/" + this.SessionUser.VartualPath + "/Pcfiles/" + row["chvSectionMainPic"].ToString();
                    }
                    else
                    {
                        if (bolShowInIndex == true)
                        {
                            row["chvSectionMainPic"] = "Pcfiles/" + row["chvSectionMainPic"].ToString();
                        }
                        else
                        {
                            row["chvSectionMainPic"] = "../Pcfiles/" + row["chvSectionMainPic"].ToString();
                        }
                    }
                }
                else
                {
                    if (SessionUser.EnableParentPath)
                    {
                        row["chvSectionMainPic"] = "/news/" + this.SessionUser.VartualPath + "/Pcfiles/default.jpg";
                    }
                    else
                    {
                        if (bolShowInIndex == true)
                        {
                            row["chvSectionMainPic"] = "Pcfiles/default.jpg";
                        }
                        else
                        {
                            row["chvSectionMainPic"] = "../Pcfiles/default.jpg";
                        }
                    }
                }

                writer.WriteStartElement("Section");


                // 添加数据库字段值
                for (int j = 0; j < tblTmp.Columns.Count; j++)
                {
                    if (row[j] != DBNull.Value)
                    {
                        writer.WriteStartElement(tblTmp.Columns[j].ColumnName);
                        writer.WriteCData(row[j].ToString());
                        writer.WriteEndElement();
                    }
                }
                if (bolContainArticle == true)
                {
                    writer.WriteStartElement("Articles");
                    string strArticleXml = this.GetSinglePageArticleXML(-1, "", false, false, false, objSessionUser, Convert.ToInt32(row["intSectionID"].ToString()), null, null);
                    writer.WriteRaw(strArticleXml);
                    writer.WriteEndElement();
                }

                SectionsFactory objSectionsFactory = new SectionsFactory();
                BusinessRules.Sections objSecctions = objSectionsFactory.CreatorBySql(string.Format(" intParentID ={0}  Order By intSortNo desc,dtmInTime asc ", row["intSectionID"]));
                if (objSecctions != null)
                {
                    objSecctions.SessionUser = this.SessionUser;
                    //GetSectionListRecursionXml(intSectionID, bolShowInIndex);
                    writer.WriteStartElement("Children");
                    string strInnerxml = GetSectionListRecursionXml(Convert.ToInt32(row["intSectionID"].ToString()), bolShowInIndex, false, bolContainArticle, objSessionUser);
                    writer.WriteRaw(strInnerxml);
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();
            }


            if (startXmlDoc == true)
            {
                writer.WriteEndElement();
                writer.WriteEndDocument();
            }
            return strXml.ToString();
        }
        /// <summary>
        /// 获取子栏目列表
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="intTotalCount"></param>
        /// <param name="isBrother">是否是兄弟栏目列表</param>
        /// <returns></returns>
        public void GetSubSectionXml(XmlTextWriter writer, int intTotalCount, bool isBrother, bool bolShowInIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT intSectionID,chvSTCName, dtmInTime, txtSTMemo, chvSectionMainPic,chvFullPath,chvSTEName , txtSeoKeywords , txtSeoTitle , txtSeodescription , chvParentPath , chvPageName, intReferSectionID , txtRemarks , chvRedirectUrl   FROM [Sections] Where ");
            if (isBrother == true)
                strSql.AppendFormat(" intParentID={0}  Order By intSortNo desc,dtmInTime desc ", this.DataItem.intSectionID);
            if (isBrother == false)
                strSql.AppendFormat("  Order By intSortNo desc,dtmInTime desc ");

            DataTable tblTmp = this.m_Access.ExecuteDataTable(strSql.ToString());
            if (tblTmp.Rows.Count > 0)
            {
                foreach (DataRow objrow in tblTmp.Rows)
                {
                    writer.WriteStartElement("chvSubSection");
                    if (SessionUser.EnableParentPath)
                    {
                        string strParentPath = (objrow["chvParentPath"] == DBNull.Value ? "shtml\\" : (objrow["chvParentPath"].ToString().Trim() == "" ? "" : objrow["chvParentPath"].ToString() + "\\"));
                        if (objrow["chvPageName"] != DBNull.Value)
                        {
                            if (string.IsNullOrEmpty(objrow["chvPageName"].ToString().Trim()))
                            {
                                if (strParentPath == "")
                                {
                                    strParentPath = "shtml\\";
                                }
                            }
                        }
                        if (SessionUser.WebSiteLevel != 1)
                        {
                            strParentPath = SessionUser.VartualPath + "\\" + strParentPath;
                        }

                        if (!System.IO.Directory.Exists(SessionUser.IssuePath + strParentPath))
                        {
                            System.IO.Directory.CreateDirectory(SessionUser.IssuePath + strParentPath);
                        }

                        objrow["chvFullPath"] = "/" + strParentPath.Replace("\\", "/") + (objrow["chvPageName"] == DBNull.Value ? "T-" + objrow["intSectionID"] : (string.IsNullOrEmpty(objrow["chvPageName"].ToString().Trim()) ? "T-" + objrow["intSectionID"] : (objrow["chvPageName"] + (this.SessionUser.EnableSectionID == true ? ("-" + objrow["intSectionID"]) : "")))) + "." + Common.AppConfig.GetWebFileType();
                    }
                    else
                    {
                        if (bolShowInIndex == true)
                        {
                            objrow["chvFullPath"] = "shtml/T-" + objrow["intSectionID"].ToString() + "." + Common.AppConfig.GetWebFileType();
                        }
                        else
                        {
                            objrow["chvFullPath"] = "../shtml/T-" + objrow["intSectionID"].ToString() + "." + Common.AppConfig.GetWebFileType();
                        }
                    }

                    if (objrow["chvSectionMainPic"] != DBNull.Value)
                    {
                        if (SessionUser.EnableParentPath)
                        {
                            objrow["chvSectionMainPic"] = "/news/" + this.SessionUser.VartualPath + "/Pcfiles/" + objrow["chvSectionMainPic"].ToString();
                        }
                        else
                        {
                            if (bolShowInIndex == true)
                            {
                                objrow["chvSectionMainPic"] = "Pcfiles/" + objrow["chvSectionMainPic"].ToString();
                            }
                            else
                            {
                                objrow["chvSectionMainPic"] = "../Pcfiles/" + objrow["chvSectionMainPic"].ToString();
                            }
                        }
                    }
                    else
                    {
                        if (SessionUser.EnableParentPath)
                        {
                            objrow["chvSectionMainPic"] = "/news/" + this.SessionUser.VartualPath + "/Pcfiles/default.jpg";
                        }
                        else
                        {
                            if (bolShowInIndex == true)
                            {
                                objrow["chvSectionMainPic"] = "Pcfiles/default.jpg";
                            }
                            else
                            {
                                objrow["chvSectionMainPic"] = "../Pcfiles/default.jpg";
                            }
                        }
                    }
                    for (int j = 0; j < tblTmp.Columns.Count; j++)
                    {
                        if (objrow[j] != DBNull.Value)
                        {
                            writer.WriteStartElement(tblTmp.Columns[j].ColumnName);
                            writer.WriteCData(objrow[j].ToString());
                            writer.WriteEndElement();
                            if (tblTmp.Columns[j].ColumnName == "chvSectionMainPic")
                            {
                                writer.WriteStartElement("chvSectionMainPicBig");
                                writer.WriteCData(objrow[j].ToString().Replace("mini", ""));
                                writer.WriteEndElement();
                            }
                            //构建没有html字符的文章简介
                            if (tblTmp.Columns[j].ColumnName == "txtSTMemo")
                            {
                                writer.WriteStartElement("txtSTMemoNoHtml");
                                writer.WriteCData(ClearKeyWord.ClearHTML(objrow[j].ToString()));
                                writer.WriteEndElement();
                            }
                        }
                    }

                    writer.WriteEndElement();
                }
            }
        }

        /// <summary>
        /// 获取栏目字段相关数据的XML字符串
        /// </summary>
        /// <returns>string</returns>
        public string GetSectionXml(int intTotalCount, bool bolShowInIndex, bool bolContainChildrenSection, bool bolContainArticle)
        {
            #region

            // 创建插件字段对象
            //PluginFields objFields = null;
            //PluginFieldsFactory objPluginFactory = new PluginFieldsFactory();

            //objFields = objPluginFactory.CreatorByType(Model.Common.Plugin.PluginType.Section);
            //if (objFields.Count == 0)
            //{
            //    throw new Model.Common.CustomException(string.Format("类型为{0}的插件无数据库字段", Model.Common.Plugin.PluginType.Section));
            //}

            #endregion

            string[] aryFields = null;
            aryFields = new string[16] { "intSectionID", "chvSTCName", "chvSTEName", "chvContent", "chvSectionMainPic", "dtmInTime", "chvFullPath", "txtSTMemo", "txtSeoKeywords ", "txtSeoTitle ", "txtSeodescription ", "chvParentPath ", "chvPageName ", "intReferSectionID ", "txtRemarks ", "chvRedirectUrl " };//aryFields = objFields.GetFieldsName();

            // 根据字段数组生成sql语句
            string strSql = "SELECT ";
            for (int i = 0; i < aryFields.Length; i++)
            {
                if (i == aryFields.Length - 1)
                {
                    strSql += aryFields[i] + " ";
                }
                else
                {
                    strSql += aryFields[i] + ", ";
                }
            }
            strSql += string.Format("FROM [Sections] WHERE intSectionID = {0}  order by intSortNo desc,  dtmInTime desc ", this.DataItem.intSectionID);

            DataTable tblTmp = this.m_Access.ExecuteDataTable(strSql);

            // 此表只有一行数据(某个栏目字段属性值的一条记录)
            // 将某些字段属性值进行修改

            // 修改栏目链接
            DataRow row = tblTmp.Rows[0];
            string strWebsiteUrl = string.Empty;
            WebSiteFactory objWSFactory = new WebSiteFactory(this.m_DBManger);

            WebSite objWebsite = objWSFactory.Creator(this.DataItem.intWSID);
            if (objWebsite == null)
            {
                throw new Model.Common.CustomException(string.Format("未找到ID＝{0}的站点", this.DataItem.intWSID));
            }
            strWebsiteUrl = objWebsite.DataItem.chvWebUrl;


            if (SessionUser.EnableParentPath)
            {
                string strParentPath = (row["chvParentPath"] == DBNull.Value ? "shtml\\" : (row["chvParentPath"].ToString().Trim() == "" ? "" : row["chvParentPath"] + "\\"));
                if (row["chvPageName"] != DBNull.Value)
                {
                    if (string.IsNullOrEmpty(row["chvPageName"].ToString().Trim()))
                    {
                        if (strParentPath == "")
                        {
                            strParentPath = "shtml\\";
                        }
                    }
                }
                if (SessionUser.WebSiteLevel != 1)
                {
                    strParentPath = SessionUser.VartualPath + "\\" + strParentPath;
                }

                if (!System.IO.Directory.Exists(SessionUser.IssuePath + strParentPath))
                {
                    System.IO.Directory.CreateDirectory(SessionUser.IssuePath + strParentPath);
                }

                row["chvFullPath"] = "/" + strParentPath.Replace("\\", "/") + (row["chvPageName"] == DBNull.Value ? "T-" + row["intSectionID"] : (string.IsNullOrEmpty(row["chvPageName"].ToString().Trim()) ? "T-" + row["intSectionID"] : (row["chvPageName"] + (this.SessionUser.EnableSectionID == true ? ("-" + row["intSectionID"]) : "")))) + "." + Common.AppConfig.GetWebFileType();
            }
            else
            {
                if (bolShowInIndex == true)
                {
                    row["chvFullPath"] = "shtml/T-" + row["intSectionID"].ToString() + "." + Common.AppConfig.GetWebFileType();
                }
                else
                {
                    row["chvFullPath"] = "../shtml/T-" + row["intSectionID"].ToString() + "." + Common.AppConfig.GetWebFileType();
                }
            }

            // 修改栏目图片链接
            if (row["chvSectionMainPic"] != DBNull.Value)
            {
                if (SessionUser.EnableParentPath)
                {
                    row["chvSectionMainPic"] = "/news/" + SessionUser.VartualPath + "/Pcfiles/" + row["chvSectionMainPic"].ToString();
                }
                else
                {
                    if (bolShowInIndex == true)
                    {
                        row["chvSectionMainPic"] = "Pcfiles/" + row["chvSectionMainPic"].ToString();
                    }
                    else
                    {
                        row["chvSectionMainPic"] = "../Pcfiles/" + row["chvSectionMainPic"].ToString();
                    }
                }
            }
            StringBuilder sbXML = new StringBuilder();

            #region 生成XML

            XmlTextWriter writer = new XmlTextWriter(new System.IO.StringWriter(sbXML));
            try
            {
                writer.WriteStartDocument();
                writer.WriteStartElement("TMPL");
                writer.WriteStartElement("Section");

                // 添加数据库字段值
                for (int i = 0; i < tblTmp.Columns.Count; i++)
                {
                    if (row[i] != DBNull.Value)
                    {
                        writer.WriteStartElement(tblTmp.Columns[i].ColumnName);
                        writer.WriteCData(row[i].ToString());
                        writer.WriteEndElement();
                        if (tblTmp.Columns[i].ColumnName == "chvSectionMainPic")
                        {
                            writer.WriteStartElement("chvSectionMainPicBig");
                            writer.WriteCData(row[i].ToString().Replace("mini", ""));
                            writer.WriteEndElement();
                        }
                        //构建没有html字符的文章简介
                        if (tblTmp.Columns[i].ColumnName == "txtSTMemo")
                        {
                            writer.WriteStartElement("txtSTMemoNoHtml");
                            writer.WriteCData(ClearKeyWord.ClearHTML(row[i].ToString()));
                            writer.WriteEndElement();
                        }
                    }
                }



                // 添加变量值
                // 当前位置
                this.GetCurPosXml(writer, bolShowInIndex);

                if (bolContainArticle)
                {
                    // 下属文章列表
                    writer.WriteStartElement("Articles");
                    this.GetSinglePageArticleXML(intTotalCount, "", false, true, bolShowInIndex, SessionUser, this.DataItem.intSectionID, writer, null);
                    writer.WriteEndElement();
                }

                if (bolContainChildrenSection)
                {
                    // 子栏目列表
                    this.GetSubSectionXml(writer, intTotalCount, true, bolShowInIndex);
                }

                writer.WriteEndElement();
                writer.WriteEndElement();
                writer.WriteEndDocument();

                writer.Flush();
            }
            finally
            {
                writer.Close();
            }

            #endregion

            return sbXML.ToString();
        }

        /// <summary>
        /// 获取当前位置
        /// </summary>
        /// <param name="objWriter"></param>
        public void GetCurPosXml(XmlTextWriter objWriter, bool bolShowInIndex)
        {
            Stack objStack = new Stack();

            string strWebsiteUrl = this.ParentWebSite.DataItem.chvWebUrl;
            int intInID = this.DataItem.intSectionID;
            this.GetParentPos(strWebsiteUrl, intInID, 1, objStack, bolShowInIndex, this.SessionUser);

            while (objStack.Count != 0)
            {
                objWriter.WriteStartElement("CurPos");
                Position objPosition = (Position)objStack.Pop();
                objWriter.WriteAttributeString("href", objPosition.strHref);
                objWriter.WriteCData(objPosition.strName);
                objWriter.WriteEndElement();
            }

            XmlDocument xmldoc = new XmlDocument();
            XmlNode objxmlnode = xmldoc.CreateNode(XmlNodeType.Element, "CurPosNode", "");
            this.GetParentPos(strWebsiteUrl, intInID, 1, ref objxmlnode, bolShowInIndex, ref xmldoc);
            objWriter.WriteStartElement("CurPosnode");

            for (int i = 0; i < objxmlnode.ChildNodes.Count; i++)
            {
                objWriter.WriteStartElement(objxmlnode.ChildNodes[i].Name);
                foreach (XmlAttribute objXmlAttribute in objxmlnode.ChildNodes[i].Attributes)
                {
                    objWriter.WriteAttributeString(objXmlAttribute.Name, objXmlAttribute.Value);
                }
                objWriter.WriteEndElement();
            }
            objWriter.WriteEndElement();
        }

        /// <summary>
        /// 获取父栏目或站点的链接地址和名称
        /// </summary>
        /// <param name="intInID">输入结点ID</param>
        /// <param name="intType">结点类型 1:栏目 2:站点</param>
        /// <param name="objHash">含键为名称，值为链接的哈希表</param>
        public void GetParentPos(string strWebsiteUrl, int intInID, int intType, ref XmlNode objXmlNode, bool bolShowInIndex, ref XmlDocument xmldoc)
        {
            string strSql = string.Empty;
            string strName = string.Empty, strHref = string.Empty;

            // 栏目结点
            if (intType == 1)
            {
                int intOutID = 0, intOutType = 1;
                strSql = string.Format("SELECT chvSTCName,chvSTEName, chvFullPath, intSectionID, intParentID, intWSID, txtSeoKeywords , txtSeoTitle , txtSeodescription, chvParentPath , chvPageName, intReferSectionID , txtRemarks , chvRedirectUrl    FROM Sections WHERE intSectionID = {0}  order by intSortNo desc,  dtmInTime desc", intInID);
                DataTable tblTmp = this.m_Access.ExecuteDataTable(strSql);
                if (tblTmp.Rows.Count > 0)
                {
                    // 没有父栏目
                    if (tblTmp.Rows[0]["intParentID"].ToString() == "0")
                    {
                        intOutType = 2;	// 父结点为站点
                        intOutID = int.Parse(tblTmp.Rows[0]["intWSID"].ToString());
                        DataRow row = tblTmp.Rows[0];
                        strName = tblTmp.Rows[0]["chvSTCName"].ToString();
                        if (SessionUser.EnableParentPath)
                        {
                            string strParentPath = (row["chvParentPath"] == DBNull.Value ? "shtml\\" : (row["chvParentPath"].ToString().Trim() == "" ? "" : row["chvParentPath"] + "\\"));
                            if (row["chvPageName"] != DBNull.Value)
                            {
                                if (string.IsNullOrEmpty(row["chvPageName"].ToString().Trim()))
                                {
                                    if (strParentPath == "")
                                    {
                                        strParentPath = "shtml\\";
                                    }
                                }
                            }
                            if (SessionUser.WebSiteLevel != 1)
                            {
                                strParentPath = SessionUser.VartualPath + "\\" + strParentPath;
                            }

                            if (!System.IO.Directory.Exists(SessionUser.IssuePath + strParentPath))
                            {
                                System.IO.Directory.CreateDirectory(SessionUser.IssuePath + strParentPath);
                            }

                            row["chvFullPath"] = "/" + strParentPath.Replace("\\", "/") + (row["chvPageName"] == DBNull.Value ? "T-" + row["intSectionID"] : (string.IsNullOrEmpty(row["chvPageName"].ToString().Trim()) ? "T-" + row["intSectionID"] : (row["chvPageName"] + (this.SessionUser.EnableSectionID == true ? ("-" + row["intSectionID"]) : "")))) + "." + Common.AppConfig.GetWebFileType();
                        }
                        else
                        {
                            if (bolShowInIndex == true)
                            {
                                strHref = "shtml/T-" + tblTmp.Rows[0]["intSectionID"].ToString() + "." + Common.AppConfig.GetWebFileType();
                            }
                            else
                            {
                                strHref = "../shtml/T-" + tblTmp.Rows[0]["intSectionID"].ToString() + "." + Common.AppConfig.GetWebFileType();
                            }
                        }
                    }
                    else
                    {
                        intOutType = 1;	// 父结点为栏目
                        intOutID = int.Parse(tblTmp.Rows[0]["intParentID"].ToString());
                        strName = tblTmp.Rows[0]["chvSTCName"].ToString();
                        DataRow row = tblTmp.Rows[0];
                        if (SessionUser.EnableParentPath)
                        {
                            string strParentPath = (row["chvParentPath"] == DBNull.Value ? "shtml\\" : (row["chvParentPath"].ToString().Trim() == "" ? "" : row["chvParentPath"] + "\\"));
                            if (row["chvPageName"] != DBNull.Value)
                            {
                                if (string.IsNullOrEmpty(row["chvPageName"].ToString().Trim()))
                                {
                                    if (strParentPath == "")
                                    {
                                        strParentPath = "shtml\\";
                                    }
                                }
                            }
                            if (SessionUser.WebSiteLevel != 1)
                            {
                                strParentPath = SessionUser.VartualPath + "\\" + strParentPath;
                            }

                            if (!System.IO.Directory.Exists(SessionUser.IssuePath + strParentPath))
                            {
                                System.IO.Directory.CreateDirectory(SessionUser.IssuePath + strParentPath);
                            }

                            row["chvFullPath"] = "/" + strParentPath.Replace("\\", "/") + (row["chvPageName"] == DBNull.Value ? "T-" + row["intSectionID"] : (string.IsNullOrEmpty(row["chvPageName"].ToString().Trim()) ? "T-" + row["intSectionID"] : (row["chvPageName"] + (this.SessionUser.EnableSectionID == true ? ("-" + row["intSectionID"]) : "")))) + "." + Common.AppConfig.GetWebFileType();
                        }
                        else
                        {
                            if (bolShowInIndex == true)
                            {
                                strHref = "shtml/T-" + tblTmp.Rows[0]["intSectionID"].ToString() + "." + Common.AppConfig.GetWebFileType();
                            }
                            else
                            {
                                strHref = "../shtml/T-" + tblTmp.Rows[0]["intSectionID"].ToString() + "." + Common.AppConfig.GetWebFileType();
                            }
                        }
                    }
                    XmlNode objChildNode = xmldoc.CreateNode(XmlNodeType.Element, "posnode", "");
                    XmlAttribute objXmlAttributeName = xmldoc.CreateAttribute("chvtitle");
                    objXmlAttributeName.Value = strName;
                    XmlAttribute objXmlAttributehref = xmldoc.CreateAttribute("href");
                    objXmlAttributehref.Value = strHref;

                    objChildNode.Attributes.Append(objXmlAttributeName);
                    objChildNode.Attributes.Append(objXmlAttributehref);
                    objXmlNode.InsertBefore(objChildNode, objXmlNode.FirstChild);

                    using (SectionsFactory objSectionsFactory = new SectionsFactory())
                    {
                        //if (intOutID != 0)
                        //{
                        Sections objSections = objSectionsFactory.CreatorBySql(" intParentID=" + intOutID);
                        if (objSections != null)
                        {
                            // 递归调用
                            this.GetParentPos(strWebsiteUrl, intOutID, intOutType, ref objXmlNode, bolShowInIndex, ref xmldoc);
                        }
                        //}
                    }
                }
            }
            // 取站点相关信息
            else
            {
                strSql = string.Format("SELECT chvName, chvWebUrl FROM WebSite WHERE intWebSiteID = {0}", intInID);
                DataTable tblTmp = this.m_Access.ExecuteDataTable(strSql);
                strName = tblTmp.Rows[0]["chvName"].ToString();
                strHref = tblTmp.Rows[0]["chvWebUrl"].ToString();

                XmlNode objChildNode = xmldoc.CreateNode(XmlNodeType.Element, "webnode", "");
                XmlAttribute objXmlAttributeName = xmldoc.CreateAttribute("chvName");
                objXmlAttributeName.Value = strName;
                XmlAttribute objXmlAttributehref = xmldoc.CreateAttribute("chvWebUrl");
                objXmlAttributehref.Value = strHref;

                objChildNode.Attributes.Append(objXmlAttributeName);
                objChildNode.Attributes.Append(objXmlAttributehref);
                objXmlNode.InsertBefore(objChildNode, objXmlNode.FirstChild);
            }
        }

        /// <summary>
        /// 获取父栏目或站点的链接地址和名称
        /// </summary>
        /// <param name="intInID">输入结点ID</param>
        /// <param name="intType">结点类型 1:栏目 2:站点</param>
        /// <param name="objHash">含键为名称，值为链接的哈希表</param>
        public void GetParentPos(string strWebsiteUrl, int intInID, int intType, Stack objStack, bool bolShowInIndex, SessionUser SessionUser)
        {
            string strSql = string.Empty;
            string strName = string.Empty, strHref = string.Empty;

            // 栏目结点
            if (intType == 1)
            {
                int intOutID = 0, intOutType = 1;
                strSql = string.Format("SELECT chvSTCName,chvSTEName, chvFullPath, intSectionID, intParentID, intWSID, txtSeoKeywords , txtSeoTitle , txtSeodescription,chvParentPath,chvPageName  FROM Sections WHERE intSectionID = {0}  order by intSortNo desc,  dtmInTime desc", intInID);
                DataTable tblTmp = this.m_Access.ExecuteDataTable(strSql);
                if (tblTmp.Rows.Count > 0)
                {
                    // 没有父栏目
                    if (tblTmp.Rows[0]["intParentID"].ToString() == "0")
                    {
                        intOutType = 2;	// 父结点为站点
                        intOutID = int.Parse(tblTmp.Rows[0]["intWSID"].ToString());
                        DataRow row = tblTmp.Rows[0];
                        strName = tblTmp.Rows[0]["chvSTCName"].ToString();
                        if (SessionUser.EnableParentPath)
                        {
                            string strParentPath = (row["chvParentPath"] == DBNull.Value ? "shtml\\" : (row["chvParentPath"].ToString().Trim() == "" ? "" : row["chvParentPath"].ToString() + "\\"));
                            if (row["chvPageName"] != DBNull.Value)
                            {
                                if (string.IsNullOrEmpty(row["chvPageName"].ToString().Trim()))
                                {
                                    if (strParentPath == "")
                                    {
                                        strParentPath = "shtml\\";
                                    }
                                }
                            }
                            if (SessionUser.WebSiteLevel != 1)
                            {
                                strParentPath = SessionUser.VartualPath + "\\" + strParentPath;
                            }

                            if (!System.IO.Directory.Exists(SessionUser.IssuePath + strParentPath))
                            {
                                System.IO.Directory.CreateDirectory(SessionUser.IssuePath + strParentPath);
                            }

                            row["chvFullPath"] = "/" + strParentPath.Replace("\\", "/") + (row["chvPageName"] == DBNull.Value ? "T-" + row["intSectionID"] : (string.IsNullOrEmpty(row["chvPageName"].ToString().Trim()) ? "T-" + row["intSectionID"] : (row["chvPageName"] + (this.SessionUser.EnableSectionID == true ? ("-" + row["intSectionID"]) : "")))) + "." + Common.AppConfig.GetWebFileType();
                        }
                        else
                        {
                            if (bolShowInIndex == true)
                            {
                                strHref = "shtml/T-" + tblTmp.Rows[0]["intSectionID"].ToString() + "." + Common.AppConfig.GetWebFileType();
                            }
                            else
                            {
                                strHref = "../shtml/T-" + tblTmp.Rows[0]["intSectionID"].ToString() + "." + Common.AppConfig.GetWebFileType();
                            }
                        }
                    }
                    else
                    {
                        intOutType = 1;	// 父结点为栏目
                        intOutID = int.Parse(tblTmp.Rows[0]["intParentID"].ToString());
                        strName = tblTmp.Rows[0]["chvSTCName"].ToString();
                        DataRow row = tblTmp.Rows[0];
                        if (SessionUser.EnableParentPath)
                        {
                            string strParentPath = (row["chvParentPath"] == DBNull.Value ? "shtml\\" : (row["chvParentPath"].ToString().Trim() == "" ? "" : row["chvParentPath"].ToString() + "\\"));
                            if (row["chvPageName"] != DBNull.Value)
                            {
                                if (string.IsNullOrEmpty(row["chvPageName"].ToString().Trim()))
                                {
                                    if (strParentPath == "")
                                    {
                                        strParentPath = "shtml\\";
                                    }
                                }
                            }
                            if (SessionUser.WebSiteLevel != 1)
                            {
                                strParentPath = SessionUser.VartualPath + "\\" + strParentPath;
                            }

                            if (!System.IO.Directory.Exists(SessionUser.IssuePath + strParentPath))
                            {
                                System.IO.Directory.CreateDirectory(SessionUser.IssuePath + strParentPath);
                            }

                            row["chvFullPath"] = "/" + strParentPath.Replace("\\", "/") + (row["chvPageName"] == DBNull.Value ? "T-" + row["intSectionID"] : (string.IsNullOrEmpty(row["chvPageName"].ToString().Trim()) ? "T-" + row["intSectionID"] : (row["chvPageName"] + (this.SessionUser.EnableSectionID == true ? ("-" + row["intSectionID"]) : "")))) + "." + Common.AppConfig.GetWebFileType();
                        }
                        else
                        {
                            if (bolShowInIndex == true)
                            {
                                strHref = "shtml/T-" + tblTmp.Rows[0]["intSectionID"].ToString() + "." + Common.AppConfig.GetWebFileType();
                            }
                            else
                            {
                                strHref = "../shtml/T-" + tblTmp.Rows[0]["intSectionID"].ToString() + "." + Common.AppConfig.GetWebFileType();
                            }
                        }
                    }
                    Position objPosition = new Position(strName, strHref);
                    objStack.Push(objPosition);

                    // 递归调用
                    this.GetParentPos(strWebsiteUrl, intOutID, intOutType, objStack, bolShowInIndex, this.SessionUser);
                }
            }
            // 取站点相关信息
            else
            {
                strSql = string.Format("SELECT chvName, chvWebUrl FROM WebSite WHERE intWebSiteID = {0}", intInID);
                DataTable tblTmp = this.m_Access.ExecuteDataTable(strSql);
                strName = tblTmp.Rows[0]["chvName"].ToString();
                strHref = tblTmp.Rows[0]["chvWebUrl"].ToString();
                Position objPosition = new Position(strName, strHref);
                objStack.Push(objPosition);
                return;
            }
        }

        private ArrayList GetSectionIDs(int intSectionID, bool isBrother)
        {
            ArrayList objArrayList = new ArrayList();
            using (SectionsFactory objFactory = new SectionsFactory())
            {
                Sections objSection = null;
                if (isBrother == true)
                    objSection = objFactory.CreatorByBrotherSectionID(intSectionID);
                else
                    objSection = objFactory.CreatorByChildSectionID(intSectionID);
                if (objSection != null)
                {
                    foreach (Model.Data.SectionsData.SectionsRow objRow in objSection.Data.Sections.Rows)
                    {
                        objArrayList.Add(objRow.intSectionID);
                    }
                }
            }
            return objArrayList;
        }

        public static int GetParentSectionID(int intCurrentSectionID)
        {
            int intResult = -1;
            using (SectionsFactory objSectionsFactory = new SectionsFactory())
            {
                Sections objSections = objSectionsFactory.Creator(intCurrentSectionID);
                if (objSections != null)
                {
                    if (!objSections.DataItem.IsintParentIDNull())
                    {
                        if (objSections.DataItem.intParentID != 0)
                        {
                            intResult = objSections.DataItem.intParentID;
                        }
                    }
                }
            }
            return intResult;
        }

        public static void GetParentSectionID(int intCurrentSectionID, int intGoToParentLevel, ref int intResult)
        {
            using (SectionsFactory objSectionsFactory = new SectionsFactory())
            {
                Sections objSections = objSectionsFactory.Creator(intCurrentSectionID);
                if (objSections != null)
                {
                    if (!objSections.DataItem.IsintParentIDNull())
                    {
                        if (objSections.DataItem.intParentID > 0)
                        {
                            if (intGoToParentLevel > 0)
                            {
                                GetParentSectionID(objSections.DataItem.intParentID, intGoToParentLevel - 1, ref intResult);
                            }
                            else
                            {
                                intResult = objSections.DataItem.intSectionID;
                            }
                        }
                        else
                        {
                            intResult = objSections.DataItem.intSectionID;
                        }
                    }
                }
                else
                {
                    throw new Exception(" 栏目ID为" + intCurrentSectionID + "不存在 请检查栏目设置");
                }
            }
        }

        //递归查找栏目引用源
        public static void FindSectionReferRoot(int intCurrentSectionId, ref int intResult)
        {
            using (BusinessLogic.ClassFactory.SectionsFactory objSectionsFactory = new SectionsFactory())
            {
                try
                {
                    BusinessLogic.BusinessRules.Sections objSections = objSectionsFactory.Creator(intCurrentSectionId);
                    if (objSections != null)
                    {
                        if (!objSections.DataItem.IsintStateReferNull())
                        {
                            if (objSections.DataItem.intStateRefer == (int)Common.Utility.StateRefer.Yes)
                            {
                                if (objSections.DataItem.intReferSectionID == objSections.DataItem.intSectionID)
                                {
                                    intResult = objSections.DataItem.intSectionID;
                                }
                                else
                                {
                                    FindSectionReferRoot(objSections.DataItem.intReferSectionID, ref intResult);
                                }
                            }
                            else
                            {
                                intResult = objSections.DataItem.intSectionID;
                            }
                        }
                        else
                        {
                            intResult = objSections.DataItem.intSectionID;
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    objSectionsFactory.Dispose();
                }
            }
        }
    }
}